/*
 * @Author       : super-J
 * @Date         : 2022-04-01 16:12:37
 * @LastEditTime : 2022-04-02 15:41:09
 * @LastEditors  : super-J
 * @Description  :
 */
import HTTPREQUEST from "./http"
import { getBaseUrl } from "./baseUrl";
import Taro from "@tarojs/taro";
import { getStorage } from "../pages/components/utils";
const storage = getStorage();

export const transmitFormData = (data, loading = false) => HTTPREQUEST.transmitFormData(data, loading)//小程序内formData请求（小程序不支持formData请求，走校园通代理）

export const get = (url, data?, header?, loading?) => HTTPREQUEST.transmitGet(`${url}`, data, header, loading)
export const post = (url, data?, header?, loading?) => HTTPREQUEST.transmitPost(`${url}`, data, header, loading)
export const put = (url, data?, header?, loading?) => HTTPREQUEST.transmitPut(`${url}`, data, header, loading)
export const del = (url, data?, header?, loading?) => HTTPREQUEST.transmitDelete(`${url}`, data, header, loading)

type ResultType<T> = { error: number, msg: string, data: T };

//统一处理http&业务response
async function responseHandler<T>(response: Promise<ResultType<T>>, showToast: boolean = false): Promise<any> {
   //HTTP请求层response统一处理
   let res: ResultType<T> | null = null
   try {
      res = await response;
   } catch (err) {
      //默认无异常弹窗提示
      if (showToast) {
         await Taro.showToast({ icon: 'none', title: "网络错误" })
      }
      throw new Error("网络错误")//与业务（接口）层统一catch处理异常
   }
   return res

   // //业务（接口）层result返回统一处理
   // if (res.error === 0 || res.error === 1) {
   //    return res.data
   // }
   // let message = res.msg || "服务器异常";
   // if (showToast) {
   //    // console.log("fashowToast112lse",showToast,message,res)
   //    await Taro.showToast({icon: 'none', title: message})
   // }
   // throw new Error(message)//与http层统一catch处理异常
};

//获取单个子系统信息
export const getSubsystemBySchoolIDAndSubID = (urlParams) => responseHandler<{ data: object }>(get(`${getBaseUrl()}/schoolSubsystem/getSubsystemBySchoolIDAndSubID`, urlParams));




//锁控
export const API_lockerCheck = (data, header) => responseHandler(get(`${getBaseUrl()}/api/commons/locker/check`, data, header))

//获取学校及系统信息
export const API_getSchoolSystemInfo = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/system/info`, data, header))
//通过 Token 获取用户信息
// export const API_getUserInfo = (data, header) => responseHandler(get(`${getBaseUrl()}/api/commons/school/user/self`, data, header))
export const API_getUserInfo = (data, header) => responseHandler(get(`${getBaseUrl()}/api/common/user`, data, header))

//===========选择对象接口===========
//获取身份列表（用于获取管理员类型）
export const API_getIdentityList = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/identity/list`, data, header))
//获取指定身份用户列表
export const API_getUserIdentity = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/user/identity`, data, header))
//获取学院列表（大学）
export const API_getCollegeList = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/college/list`, data, header))
//获取专业列表（大学）
export const API_getMajorList = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/major/list`, data, header))
//获取我的院系教师（大学）
export const API_getMyCollegeTeacher = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/user/collegeTeachers`, data, header))
//获取我的院系班级（大学）
export const API_getMyCollegeClass = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/class/college`, data, header))
//获取我的院系班级学生（大学）
export const API_getMyCollegeStudent = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/user/students`, data, header))
//获取教学组列表（区分大中小学）
export const API_getGroupList = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/group/list`, data, header))
//获取教师列表
export const API_getUserTeachers = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/user/teachers`, data, header))
//获取年级列表（区分大中小学）
export const API_getGradeList = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/grade/list`, data, header))
//获取班级列表（区分大中小学）
export const API_getClassList = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/class/list`, data, header))
//获取学生列表
export const API_getUserStudents = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/user/students`, data, header))
//获取家长列表
export const API_getUserParents = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/user/parents`, data, header))
// //获取部门及列表
// export const API_getDepartmentList = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/department/list`, data, header))
//获取部门及列表（新）
export const API_getDepartmentList = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/department/tree`, data, header))
//获取部门员工列表
export const API_getDepartmentStaffs = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/user/department/staffs`, data, header))

//获取我的班级列表
export const API_getClassMine = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/class/mine`, data, header))
//获取我的教学组列表
export const API_getGroupMine = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/school/group/mine`, data, header))

//搜索用户
export const API_getUserSearch = (data, header) => responseHandler(get(`${getBaseUrl()}/api/commons/school/user/search`, data, header))

//======================================================================================
//保存公告
export const API_saveNotice = (data, header) => responseHandler(post(`${getBaseUrl()}/api/notice/created/save`, data, header))
//发布公告
export const API_releaseNotice = (data, header) => responseHandler(post(`${getBaseUrl()}/api/notice/created/release`, data, header))
//条件分页搜索发布者公告
export const API_getNoticeList = (data, pageNum, pageSize, header?) => responseHandler(get(`${getBaseUrl()}/api/notice/list/creator/page/${pageNum}/${pageSize}`, data, header))
//删除公告
export const API_delNotice = (data, header) => responseHandler(del(`${getBaseUrl()}/api/notice/manage/del`, data, header))
//撤回公告
export const API_callbackNotice = (data, header) => responseHandler(put(`${getBaseUrl()}/api/notice/manage/callback`, data, header))
//获取需要编辑的公告的信息
export const API_getEditDetail = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/notice/info/edit/detail`, data, header))
//获取敏感词
export const API_sensitiveData = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/sensitiveWord/list/word`, data, header))
//发布者查看已发布公告详情
// export const API_getReadDetail = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/notice/info/creator/read/detail`, data, header))
export const API_getReadDetail = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/notice/info/release/detail`, data, header))
//发布者查看未发布公告详情
export const API_getNoReadDetail = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/notice/info/edit/detail`, data, header))
/**获取接收者的分组信息*/
export const API_getReceiverGroup = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/notice/receiver/struct/info`, data, header))
// export const API_getReceiverGroup = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/notice/statistics/receiver/group`, data, header))

/**条件分页获取接收者读取信息 */
export const API_getReceiverInfoByPage = (data, pageNum, pageSize, header?) => responseHandler(get(`${getBaseUrl()}/api/notice/receiver/page/read/progress/detail/${pageNum}/${pageSize}`, data, header))
/**催读 */
export const API_urgeRead = (data, header) => responseHandler(post(`${getBaseUrl()}/api/notice/manage/urge/read`, data, header))
// 导出
export const API_exportNotices = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/notice/excel/export/user/released`, data, header))

//移动端批量上传文件
// export const API_upload = (data, header) => responseHandler(get(`${getBaseUrl()}/api/commons/file/mobile/batch/upload`, data, header))
export const API_upload = (data, header) => responseHandler(get(`${getBaseUrl()}edu-office-platform/api/commons/file/upload`, data, header))

//刷新选择对象
export const API_receiverCache = (data, header) => responseHandler(del(`${getBaseUrl()}/api/commons/wipe/receiver/cache`, data, header))

/**楼牌 */
export const API_getBuildingBoards = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/device/building/boards`, data, header))
/**班牌 */
export const API_getClassBoards = (data, header?) => responseHandler(get(`${getBaseUrl()}/api/commons/device/class/boards`, data, header))
/**广播终端 */
export const API_getRadioBroadcasts = (data, header) => responseHandler(get(`${getBaseUrl()}/api/commons/device/radio/broadcasts`, data, header))


//小程序使用的接口=========================================
/**敏感信息检查 */
export const API_noticeCheck = (data, header) => responseHandler(post(`${getBaseUrl()}/api/notice/created/check`, data, header))